//-----------------------------------------------------------------------
// <copyright file="a_WearTypeDAOBase.cs" company="AACECOM">
//     Copyright (c) AACECOM. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

using System;
using System.Data;
using System.Data.Common;
using System.Collections;
using Microsoft.Practices.EnterpriseLibrary.Data;
using ThoiTrang.Entities;

namespace ThoiTrang.Data
{    
    public abstract class a_WearTypeDAOBase
    {
        #region Common methods
        public virtual a_WearType Createa_WearTypeFromReader(IDataReader reader)
        {
            a_WearType item = new a_WearType();
            try
            {
                if (!reader.IsDBNull(reader.GetOrdinal("WTypeID"))) item.WTypeID = (int)reader["WTypeID"];
                if (!reader.IsDBNull(reader.GetOrdinal("WearTypeNameVN"))) item.WearTypeNameVN = (string)reader["WearTypeNameVN"];
                if (!reader.IsDBNull(reader.GetOrdinal("WearTypeNameEN"))) item.WearTypeNameEN = (string)reader["WearTypeNameEN"];
            }
            catch (Exception ex)
            {                
                throw ex;
            }
            return item;
        }
        #endregion
        
        #region Createa_WearType methods
            
        public virtual void Createa_WearType(a_WearType a_WearType)
        {
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_WearTypes_ins");
                
                database.AddInParameter(dbCommand, "@WearTypeNameVN", DbType.String, a_WearType.WearTypeNameVN);
                database.AddInParameter(dbCommand, "@WearTypeNameEN", DbType.AnsiString, a_WearType.WearTypeNameEN);
                database.AddOutParameter(dbCommand, "@WTypeID", DbType.Int32, 0);
                
                database.ExecuteNonQuery(dbCommand);
                a_WearType.WTypeID = (int)database.GetParameterValue(dbCommand, "@WTypeID");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        #endregion

        #region Updatea_WearType methods
        
        public virtual void Updatea_WearType(a_WearType a_WearType)
        {
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_WearTypes_upd");            
                
                database.AddInParameter(dbCommand, "@WTypeID", DbType.Int32, a_WearType.WTypeID);
                database.AddInParameter(dbCommand, "@WearTypeNameVN", DbType.String, a_WearType.WearTypeNameVN);
                database.AddInParameter(dbCommand, "@WearTypeNameEN", DbType.AnsiString, a_WearType.WearTypeNameEN);
                
                database.ExecuteNonQuery(dbCommand);
            }
            catch (Exception ex)
            {
               throw ex;
            }
        }
        
        #endregion

        #region Deletea_WearType methods
        public virtual void Deletea_WearType(int wTypeID)
        {
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_WearTypes_del");
                
                database.AddInParameter(dbCommand, "@WTypeID", DbType.Int32, wTypeID);
                
                database.ExecuteNonQuery(dbCommand);
            }
            catch (Exception ex)
            {
               throw ex;
            }
        }

        #endregion

        #region Geta_WearType methods
        
        public virtual a_WearType Geta_WearType(int wTypeID)
        {            
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_WearTypes_sel");
                
                database.AddInParameter(dbCommand, "@WTypeID", DbType.Int32, wTypeID);
                
                a_WearType a_WearType =  null;
                using (IDataReader reader = database.ExecuteReader(dbCommand))
                {
                    if (reader.Read())
                    {
                        a_WearType = Createa_WearTypeFromReader(reader);
                        reader.Close();
                    }
                }
                return a_WearType;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        
        #endregion

        #region Geta_WearTypeList methods
        public virtual a_WearTypeCollection Geta_WearTypeList(a_WearTypeColumns orderBy, OrderDirection orderDirection, int page, int pageSize, out int totalRecords)
        {            
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_WearTypes_selList");
                
                database.AddInParameter(dbCommand, "@OrderBy", DbType.AnsiString, orderBy.ToString());
                database.AddInParameter(dbCommand, "@OrderDirection", DbType.AnsiString, orderDirection.ToString());
                database.AddInParameter(dbCommand, "@Page", DbType.Int32, page);
                database.AddInParameter(dbCommand, "@PageSize", DbType.Int32, pageSize);
                database.AddOutParameter(dbCommand, "@TotalRecords", DbType.Int32, 4);
                
                a_WearTypeCollection a_WearTypeCollection = new a_WearTypeCollection();
                using (IDataReader reader = database.ExecuteReader(dbCommand))
                {
                    while (reader.Read())
                    {
                        a_WearType a_WearType = Createa_WearTypeFromReader(reader);
                        a_WearTypeCollection.Add(a_WearType);
                    }
                    reader.Close();
                }
                totalRecords = (int)database.GetParameterValue(dbCommand, "@TotalRecords");
                return a_WearTypeCollection;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        
        public virtual a_WearTypeCollection Geta_WearTypeList(a_WearTypeColumns orderBy, OrderDirection orderDirection)
        {            
            int totalRecords = 0;
            return Geta_WearTypeList(orderBy, orderDirection, 0, 0, out totalRecords);
        }
        
        #endregion

        #region Geta_WearTypeList methods
        public virtual a_WearTypeCollection Geta_WearTypeList_alphabet(string mychar, a_WearTypeColumns orderBy, OrderDirection orderDirection, int page, int pageSize, out int totalRecords)
        {
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_WearTypes_selList_alphabet");
                database.AddInParameter(dbCommand, "@Mychar", DbType.AnsiString, mychar);
                database.AddInParameter(dbCommand, "@OrderBy", DbType.AnsiString, orderBy.ToString());
                database.AddInParameter(dbCommand, "@OrderDirection", DbType.AnsiString, orderDirection.ToString());
                database.AddInParameter(dbCommand, "@Page", DbType.Int32, page);
                database.AddInParameter(dbCommand, "@PageSize", DbType.Int32, pageSize);
                database.AddOutParameter(dbCommand, "@TotalRecords", DbType.Int32, 4);

                a_WearTypeCollection a_WearTypeCollection = new a_WearTypeCollection();
                using (IDataReader reader = database.ExecuteReader(dbCommand))
                {
                    while (reader.Read())
                    {
                        a_WearType a_WearType = Createa_WearTypeFromReader(reader);
                        a_WearTypeCollection.Add(a_WearType);
                    }
                    reader.Close();
                }
                totalRecords = (int)database.GetParameterValue(dbCommand, "@TotalRecords");
                return a_WearTypeCollection;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public virtual a_WearTypeCollection Geta_WearTypeList_alphabet(string mychar, a_WearTypeColumns orderBy, OrderDirection orderDirection)
        {
            int totalRecords = 0;
            return Geta_WearTypeList_alphabet(mychar, orderBy, orderDirection, 0, 0, out totalRecords);
        }

        #endregion
    }
}